package cn.tedu.collection;/**
 * @Author 金帮嘉诚 @Date 2021-06-23 星期三 20:34
 */
/*本类用于测试LinkedList*/

import java.util.LinkedList;

/**
 * 知识点
 * LinkedList有很多对首位元素进行操作的方法，特征是方法名含有First或Last
 * 特有方法：方法名后加First Last
 * add
 * get
 * remove
 * <p>
 * 查询、新增、删除
 * peek
 * offer
 * poll
 */
public class TestLinkedList {
    public static void main(String[] args) {
        LinkedList<String> l1=new LinkedList<>();
        l1.add("海绵宝宝");
        l1.add("海绵宝宝啊");
        l1.add("海绵宝宝");
        l1.add("海绵宝宝哦");

        System.out.println("l1 = " + l1);
        //返回值为String
//        System.out.println("l1.addFirst(\"派大星\") = " + l1.addFirst("派大星"));
        l1.addFirst("派大星");
        System.out.println("l1 = " + l1);
        l1.addLast("派大星");
        System.out.println("l1 = " + l1);

        System.out.println("l1.getFirst() = " + l1.getFirst());
        System.out.println("l1.getLast() = " + l1.getLast());

        System.out.println("l1.removeFirst() = " + l1.removeFirst());
        System.out.println("l1 = " + l1);
        System.out.println("l1.removeLast() = " + l1.removeLast());
        System.out.println("l1 = " + l1);

        LinkedList<String> l2=new LinkedList<>();
        l2.addLast("三体1");
        l2.addLast("三体2");
        l2.addLast("三体3");
        l2.addLast("叶文洁");
        l2.addLast("汪淼");
        l2.addLast("罗辑");

        //查询
        System.out.println("l2 = " + l2);
        System.out.println("l2.peek() = " + l2.peek());
        System.out.println("l2.peekFirst() = " + l2.peekFirst());
        System.out.println("l2.peekLast() = " + l2.peekLast());
        System.out.println("l2 = " + l2);
        //增加
        System.out.println("l2.offer(\"程心\") = " + l2.offer("程心"));
        System.out.println("l2 = " + l2);
        System.out.println("l2.offerFirst(\"大史\") = " + l2.offerFirst("大史"));
        System.out.println("l2 = " + l2);
        System.out.println("l2.offerLast(\"艾AA\") = " + l2.offerLast("艾AA"));
        System.out.println("l2 = " + l2);
        //删除
        System.out.println("l2.poll() = " + l2.poll());
        System.out.println("l2 = " + l2);
        System.out.println("l2.pollFirst() = " + l2.pollFirst());
        System.out.println("l2 = " + l2);
        System.out.println("l2.pollLast() = " + l2.pollLast());
        System.out.println("l2 = " + l2);


    }
}
